package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class GeoAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const GEO_GET_EVENTS:String     = "geo.getEvents";
        public static const GEO_GET_TOP_ARTISTS:String = "geo.getTopArtists";
        public static const GEO_GET_TOP_TRACKS:String  = "geo.getTopTracks";
        
        public function GeoAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        
        /** geo.getEvents */
        public function getEvents(onComplete:Function, 
                                   onError:Function,
                                   location:String=null,
                                   lat:String=null,
                                   long:String=null,
                                   page:int=-1,
                                   distance:Number=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = GeoAPI.GEO_GET_EVENTS;
            if (location!=null) urlVars["location"] = location;
            if (lat!=null)      urlVars["lat"] = lat;
            if (long!=null)     urlVars["long"] = long;            
            if (page>0)  urlVars["page"]  = page;
            if (distance>0) urlVars["distance"] = distance;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        
        /** geo.getTopArtists */
        public function getTopArtists(onComplete:Function, 
                                   onError:Function,
                                   country:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = GeoAPI.GEO_GET_TOP_ARTISTS;
            urlVars["country"] = country;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** geo.getTopTracks */
        public function getTopTracks(onComplete:Function, 
                                   onError:Function,
                                   country:String,
                                   location:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = GeoAPI.GEO_GET_TOP_TRACKS;
            urlVars["country"] = country;
            if (location!=null) urlVars["location"] = location;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
    }
}